﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;

namespace ItemParser
{
    class Program
    {
        static void Main(string[] args)
        {
            String fileName = String.Empty;

            if (args.Count() > 0)
            {
                fileName = args[0];

                using (FileStream inFile = File.OpenRead(fileName))
                {
                    StreamReader inFileReader = new StreamReader(inFile);

                    FileStream outFile = File.Open("DotaItems.cs", FileMode.Create);
                    StreamWriter outFileWriter = new StreamWriter(outFile);
                    outFileWriter.AutoFlush = true;

                    String itemData = inFileReader.ReadToEnd();

                    Regex regex = new Regex(@"\[(\w{4})\]\r\nName=""(.*?)"".*?");
                    MatchCollection collection = regex.Matches(itemData);

                    foreach (Match match in collection)
                    {
                        String itemCode = match.Groups[1].Value;
                        String itemName = String.Empty;

                        Regex colorStringRegex1 = new Regex(@"\|.{9}");
                        Regex colorStringRegex2 = new Regex(@"\|r");

                        itemName = colorStringRegex1.Replace(match.Groups[2].Value, String.Empty);
                        itemName = colorStringRegex2.Replace(itemName, String.Empty);

                        outFileWriter.WriteLine(
                            String.Format("itemCodes.Add(\"{0}\", \"{1}\");",
                            itemCode,
                        itemName
                            ));
                    }
                }
            }
            else
            {
            }
        }
    }
}
